##!/usr/bin/env python3
# -*- coding: utf-8 -*-

from datetime import datetime, timezone, timedelta  #不能和文件名重名，否则import不识别


def to_timestamp(dt_str, tz_str):
    d = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
    print(d)
    tz = int(tz_str[3:-3])  # 从索引3开始取，取到倒数第3索引的前一个
    print(tz)
    dt = d.replace(tzinfo=timezone(timedelta(hours=tz)))
    return dt.timestamp()


# 测试:
t1 = to_timestamp('2015-6-1 08:10:30', 'UTC+7:00')
assert t1 == 1433121030.0, t1

t2 = to_timestamp('2015-5-31 16:10:30', 'UTC-09:00')
assert t2 == 1433121030.0, t2

print('ok')
